<?php $sessao = new Zend_Session_Namespace('Parametros'); ?>
<html lang="pt-br">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <link href="<?php echo $this->urlbase?>/public/media/css/relatorio_aluno.css" media="screen,print" rel="stylesheet" type="text/css">
</head>
<body>
    <div class="pagina">
        <div class="titulo_relatorio">
            <div class="t_r_txt">Boletim de Desempenho do Simulado</div>
            <img class="t_r_logo" src="<?php echo $this->urlbase.'/public/media/images/logo_rel.png'; ?>" />
        </div>
        <table>
            <tr>
                <th align="right">Aluno: </th>
                <th align="left"><?php echo $this->aluno['ALU_NOM'];?></th>
            </tr> 
            <tr>
                <th align="right">Curso: </th>
                <th align="left"><?php echo dominio::getTurma($this->aluno['CUR_ID'],0);?></th>
            </tr>
            <tr>
                <th align="right">Simulado: </th>
                <th align="left"><?php echo $this->simulado['PLS_NOM'];?></th>
            </tr> 
        </table>   
        <br>
        <table>
            <tr>
                <th colspan="3">Desempenho</th>
            </tr> 
            <tr>
                <th>Matéria</th>
                <th>Acertos</th>
                <th>Peso</th>
            </tr> 
            <?php 
                $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM '
                        .' FROM PUBSIM_RANALU p '
                        .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                        .' WHERE p.PLS_ID = ' . $this->PLS_ID
                        .' AND p.ALU_ID = ' . $this->ALU_ID;
                $alu = $this->db->fetchRow($query);
                if($alu['PLA_REDID'] > 0){
            ?>
            <tr>
                <td><?php echo $alu['DCP_NOM']; ?>¹</td>
                <td align="center"><?php echo $alu['PLA_REDNTAPSO']; ?></td>
                <td align="center"><?php echo tools::trunc_valor($alu['PLA_REDPSO'],0); ?></td>
            </tr> 
            <?php  } ?>
            
            <?php 
                foreach($this->result as $row){ 
                    $qtd_acerto = 0;
                    $query = 'SELECT SQL_CACHE p.PSG_ALT, r.PSR_ALT '
                            . 'FROM PUBLICACAO_SIMULADO_GABARITO p, PUBLICACAO_SIMULADO_RESPOSTA r '
                            .' WHERE p.PLS_ID = r.PLS_ID AND p.PSG_ID = r.PSG_ID'
                            .' AND p.PLS_ID = '.$this->PLS_ID.' AND r.PLS_ID = '.$this->PLS_ID
                            .' AND r.ALU_ID = '.$this->ALU_ID
                            .' AND p.DCP_ID = r.DCP_ID '
                            .' AND p.DCP_ID = '.$row['DCP_ID'].' AND r.DCP_ID = '.$row['DCP_ID']
                            .' ORDER BY p.PSG_QST';
                    $ress = $this->db->fetchAll($query);
                    foreach($ress as $res){
                        if($res['PSG_ALT'] == $res['PSR_ALT'] ){
                            $qtd_acerto++;
                        } 
                    }
                        if(count($ress) > 0){
            ?>
            <tr>
                <td><?php echo $row['DCP_NOM']; ?></td>
                <td align="center"><?php echo $qtd_acerto; ?></td>
                <td align="center"><?php echo tools::trunc_valor($row['PSG_PES'],0); ?></td>
            </tr> 
                <?php } ?>
            <?php } ?>
        </table>    
        <br>
        <table>
            <tr>
                <th>Média</th>
                <th>Classificação</th>
            </tr> 
            <tr>
                <td align="center"><?php echo $alu['PLA_POR']; ?></td>
                <td align="center"><?php echo $alu['PLA_POS']; ?></td>
            </tr> 
            <?php if($alu['PLA_REDID'] > 0){ ?>
            <tr>
                <td colspan="2">1. Nota da <?php echo $alu['DCP_NOM']; ?>: <?php echo $alu['PLA_REDNTA']; ?></td>
            </tr>
            <?php } ?>
        </table>    
        <br>
        <table>
            <tr>
                <th colspan="12">Melhor Desempenho</th>
            </tr>
            <tr>
            <?php 
            $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM, d.DCP_NOMABV '
                    .' FROM PUBSIM_RANALU p '
                    .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                    .' WHERE p.PLS_ID = ' . $this->PLS_ID
                    .' AND p.ALU_ID = ' . $this->mel['ALU_ID'];
                   
            $mel_alu = $this->db->fetchRow($query);
            if($mel_alu['PLA_REDID'] > 0){
            ?>
                <td align="center"><?php echo $mel_alu['DCP_NOMABV']; ?></td>
            <?php  } ?>
            <?php foreach($this->result as $row){ 
                $qtd_acerto = 0;
                $query = 'SELECT SQL_CACHE p.PSG_ALT, r.PSR_ALT '
                        . 'FROM PUBLICACAO_SIMULADO_GABARITO p, PUBLICACAO_SIMULADO_RESPOSTA r '
                        .' WHERE p.PLS_ID = r.PLS_ID AND p.PSG_ID = r.PSG_ID'
                        .' AND p.PLS_ID = '.$this->PLS_ID.' AND r.PLS_ID = '.$this->PLS_ID
                        .' AND r.ALU_ID = '.$this->mel['ALU_ID']
                        .' AND p.DCP_ID = r.DCP_ID '
                        .' AND p.DCP_ID = '.$row['DCP_ID'].' AND r.DCP_ID = '.$row['DCP_ID']
                        .' ORDER BY p.PSG_QST';
                $ress = $this->db->fetchAll($query);
                if(count($ress) > 0){
            ?>
                <td align="center"><?php echo $row['DCP_NOMABV']; ?></td>
            <?php } } ?>
                <td rowspan="2" align="center">Média: <?php echo $this->mel['PLA_POR']; ?></td>
            </tr> 
            <tr>
            <?php 
            $query = 'SELECT SQL_CACHE p.*, d.DCP_NOM, d.DCP_NOMABV '
                    .' FROM PUBSIM_RANALU p '
                    .' LEFT JOIN DISCIPLINA as d ON p.PLA_REDID = d.DCP_ID '
                    .' WHERE p.PLS_ID = ' . $this->PLS_ID
                    .' AND p.ALU_ID = ' . $this->mel['ALU_ID'];
            $mel_alu = $this->db->fetchRow($query);
            if($mel_alu['PLA_REDID'] > 0){
            ?>
                <td align="center"><?php echo $mel_alu['PLA_REDNTAPSO']; ?></td>
            <?php  } ?>
            <?php foreach($this->result as $row){ 
                
                $qtd_acerto = 0;
                $query = 'SELECT SQL_CACHE p.PSG_ALT, r.PSR_ALT '
                        . 'FROM PUBLICACAO_SIMULADO_GABARITO p, PUBLICACAO_SIMULADO_RESPOSTA r '
                        .' WHERE p.PLS_ID = r.PLS_ID AND p.PSG_ID = r.PSG_ID'
                        .' AND p.PLS_ID = '.$this->PLS_ID.' AND r.PLS_ID = '.$this->PLS_ID
                        .' AND r.ALU_ID = '.$this->mel['ALU_ID']
                        .' AND p.DCP_ID = r.DCP_ID '
                        .' AND p.DCP_ID = '.$row['DCP_ID'].' AND r.DCP_ID = '.$row['DCP_ID']
                        .' ORDER BY p.PSG_QST';
                $ress = $this->db->fetchAll($query);
                foreach($ress as $res){
                    if($res['PSG_ALT'] == $res['PSR_ALT'] ){
                        $qtd_acerto++;
                    } 
                }
                if(count($ress) > 0){ 
            ?>
                <td align="center"><?php echo $qtd_acerto; ?></td>
            <?php } } ?>
            </tr> 
        </table>
        <br>
    </div>
    
<script>  
window.print(); 
</script>

<body>
</html>
